<template>
  <div class="flow-box">
    <el-table
        :data="tableData"
        stripe
        style="width: 100%;height: 91vh;"
        border
        max-height="91vh"
        empty-text="暂无数据"
    >
      <el-table-column
          fixed
          prop="seal_flow_id"
          label="ID"
          width="200"
          align="center"
      />
      <el-table-column
          label="申请人"
          width="100"
          align="center"
      >
        {{userInfo.username}}
      </el-table-column>
      <el-table-column
          label="申请时间"
          width="120  "
          align="center"
      >
        <template #default="{row}">
          {{computeDate(row.created_at)}}
        </template>
      </el-table-column>
      <el-table-column
          label="状态"
          align="center"
          width="120"
      >
        <template #default="{row}">
          <el-tag type="info" v-if="row.seal_flow_status === 0">已提交</el-tag>
          <el-tag type="warning" v-else-if="row.seal_flow_status === 1">审批中</el-tag>
          <el-tag type="warning" v-else-if="row.seal_flow_status === 2">已完成</el-tag>
          <el-tag type="info" v-else-if="row.seal_flow_status === 3">已撤销</el-tag>
          <el-tag type="warning" v-else-if="row.seal_flow_status === 4">驳回待修改</el-tag>
          <el-tag type="info" v-else-if="row.seal_flow_status === 5">修改待审批</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="status"
          label="当前结果"
          align="center"
          width="120"
      >
        <template #default="{row}">
          <el-tag type="warning" v-if="row.seal_flow_result === 0">拒绝</el-tag>
          <el-tag type="success" v-else-if="row.seal_flow_result === 1">通过</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="operatorName"
          label="当前/最后审批人"
          align="center"
          width="150"
      />
      <el-table-column
          label="是否外借"
          align="center"
          width="100"
      >
        <template #default="{row}">
          <el-tag type="warning" v-if="row.seal_take === 0">否</el-tag>
          <el-tag type="success" v-else-if="row.seal_take === 1">是</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          label="是否归还"
          align="center"
          width="100"
      >
        <template #default="{row}">
          <el-tag type="warning" v-if="row.seal_flow_return === 0">未归还</el-tag>
          <el-tag type="success" v-else-if="row.seal_flow_return === 1">已归还</el-tag>
          <el-tag type="success" v-else>未借出</el-tag>
        </template>
      </el-table-column>
      <el-table-column
          prop="seal_flow_use_number"
          label="盖章次数"
          align="center"
          width="100"
      />
      <el-table-column
          label="理由/说明/备注"
          width="400"
          align="center"
      >
        <template #default="{row}">
          {{ row.details ? row.details : '-'}}
        </template>
      </el-table-column>
      <el-table-column
          label="操作"
          align="center"
      >
        <template #default="{row}">
          <el-button
              type="primary"
              size="small"
              @click="showDetails(row.seal_flow_id)"
          >
            详情
          </el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>

  <RreViewDialog ref="preRef"  @refreshRefused='getList'/>
</template>

<script setup>
import {ElButton, ElTable, ElTableColumn, ElTag} from "element-plus"
import RreViewDialog from "@/components/Common/OA/Seal/PreviewSealDialog.vue"
import {computeDate, createMsg, getUserInfo} from "@/lib/utils"
import {onMounted, ref} from "vue"
import {getMyRefusedSealApprove} from "@/api/OA/Seal"
import {useRoute, useRouter} from "vue-router"
import emitter from "@/lib/eventBus"

const route = useRoute()
const router = useRouter()

const preRef = ref()

const tableData = ref([])
let userInfo = {}

onMounted(()=>{
  emitter.emit('home_menu','/OA/seal/all')
  emitter.emit('updateMySeal','/OA/seal/rejected')
  if (route.path !== '/OA/seal/rejected') router.push('/OA/seal/rejected')
  userInfo = getUserInfo()
  getList()
})


const getList = async () => {
  try {
    const {data:res} = await getMyRefusedSealApprove(userInfo.id)
    if (res.code === 200){
      tableData.value = res.data
    } else if (res.code === 201){
      // createMsg('暂无数据','info',true)
    } else if (res.code === 400 ||res.code === 401 ||res.code === 402){
      createMsg('未查询到数据','info',true)
    }
  } catch (e) {
    console.log(e)
  }
}

const showDetails = (id) =>{
  preRef.value.showDetails(id)
}
</script>

<style scoped lang="less">
.flow-box{
  width: 99%;
  margin: 0 auto;
}
</style>
